#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 2e5 + 10;

int n;
int a[N], b[N], q[N];
int res1[N], res2[N];

int f(int x){
    int l = 1, r = n;
    while(l < r){
        int mid = l + r >> 1;
        if(b[mid] >= x){
            r = mid;
        }else{
            l = mid + 1;
        }
    }

    return l;
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        cin >> n;
        for(int i = 1; i <= n; i ++) cin >> a[i];
        for(int i = 1; i <= n; i ++) cin >> b[i];

        int tt = -1;
        // q[++tt] = n;

        for(int i = n; i >= 1; i --){
            int l = f(a[i]);
           // cout << "l: " << l << '\n';
            if(i == l){
                q[++tt] = i;
            }
        }

        // for(int i = tt; i >= 0; i--){
        //     cout << q[i] << " ";
        // }
        // cout << endl;


        for(int i = tt; i >= 0; i --){
            int maxnum = q[i - 1];
            int minnum = q[i];
            if(i == 0 && q[i] != n){
                maxnum = n + 1;
            }

            if(i == 0 && q[i] == n){
                maxnum = n + 1;
            }



            for(int j = minnum; j < maxnum; j ++){
                res1[j] = b[f(a[j])] - a[j];
                res2[j] = b[maxnum - 1] - a[j];
            }
        }

        for(int i = 1; i <= n; i ++){
            cout << res1[i] << " ";
        }
        cout << '\n';

        for(int i = 1; i <= n; i ++){
            cout << res2[i] << " ";
        }
        cout << '\n';

    }


    return 0;
}